import { Controller, Get, Post, Patch, Body, Param, Delete, Query } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Limit } from '@common/utils/constants';
import { GoodCreateDto, GoodListDto, GoodUpdateDto } from './dto';
import { GoodService } from './good.service';

@ApiTags('good')
@ApiBearerAuth()
@Controller()
export class GoodController {
    constructor(private readonly goodService: GoodService) {}
    /**
     * 新增商品表
     */
    @ApiOperation({ summary: '新增商品表' })
    @Post('/good/create')
    create(@Body() createGoodDto: GoodCreateDto) {
        return this.goodService.create(createGoodDto);
    }
    /**
     * 商品表列表（query）
     */
    @ApiOperation({ summary: '商品表列表（query）' })
    @Post('/good/list')
    queryList(@Body() dto: GoodListDto) {
        return this.goodService.list(dto);
    }
    /**
     * 商品表列表
     */
    @ApiOperation({ summary: '商品表列表' })
    @Get('/good/list')
    list(@Query() limit: Limit) {
        return this.goodService.list({ limit });
    }
    // @Get('/good')
    // findAll() {
    //     return this.goodService.findAll();
    // }
    /**
     * 商品表详情
     */
    @Get('/good/details/:id')
    @ApiOperation({ summary: '某个商品表信息' })
    @ApiResponse({
        status: 200,
        // description: 'The found record',
        // type: GetGoodInfoResult,
    })
    details(@Param('id') id: number) {
        return this.goodService.findById(id);
    }
    /**
     * 修改商品表
     */
    @Patch('/good/update/:id')
    @ApiOperation({ summary: '修改商品表信息' })
    update(@Param('id') id: number, @Body() updateGoodDto: GoodUpdateDto) {
        return this.goodService.update(id, updateGoodDto);
    }
    /**
     * 删除商品表
     */
    @ApiOperation({ summary: '删除商品表' })
    @Delete('/good/remove/:id')
    remove(@Param('id') id: string) {
        return this.goodService.delete(+id);
    }
}
